<?php
class User extends AppModel {

	var $name = 'User';
	var $validate = array(
		'username' => array('notempty'),
		'password' => array('notempty'),
		'group_id' => array('numeric')
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'Group' => array(
			'className' => 'Group',
			'foreignKey' => 'group_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
		'Post' => array(
			'className' => 'Post',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		
		'Job' => array(
			'className' => 'Job',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => array('User.group_id' => '2'),
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
	
	var $hasOne = array(
		'Resume'=> array(
			'className' => 'Resume',
			'foreignKey' => 'user_id',
			'dependent' => true,
			'conditions' => '',
			'fields' => ''),
	
		'Information'=> array(
			'className' => 'Information',
			'foreignKey' => 'user_id',
			'dependent' => true,
			'conditions' => '',
			'fields' => '')
	);	
		
	
	var $actsAs = array( 'Acl' => 'requester' ); 
	
	function parentNode () { 
		if (! $this -> id && empty( $this -> data )) { 
			return null ; 
		} 
		     $data = $this -> data ; 
		     if (empty( $this -> data )) { 
		     	         $data = $this -> read (); 
		     } 
		     if (empty( $data [ 'User' ][ 'group_id' ])) { 
		     	return null ; 
		     } else { 
		     	return array( 'Group' => array( 'id' => $data [ 'User' ][ 'group_id' ])); 
		     } 
	} 
	
	
	  /** 
		* After save callback 
		* 
		* Update the aro for the user. 
		* 
		* @access public 
		* @return void 
		*/ 
	function afterSave ( $created ) { 
		if(!$created ){ 
						$parent = $this -> parentNode (); 
		                $parent = $this -> node ( $parent ); 
		                $node = $this -> node (); 
		                $aro = $node [ 0 ]; 
		                $aro [ 'Aro' ][ 'parent_id' ] = $parent [ 0 ][ 'Aro' ][ 'id' ]; 
		                $this -> Aro -> save ( $aro ); 
		} 
	} 

}
?>